using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Mechanism2 : Mechanism
{
    public override void TriggerOn()
    {
        materialAnimation.Play(0);
        boxCollider.enabled = false;

        BlockBase blockBase = LevelManager.instance.FindLastBlock(transform.position, this);
        if (blockBase != null)
        {
            blockBase.gameObject.SetActive(true);
        }

        LevelManager.instance.BuildNavMesh();

        if (blockBase != null)
        {
            Vector3 pos = blockBase.transform.position;
            if (CameraController.cameralook == CameraLook.Right)
            {
                blockBase.transform.position -= Vector3.right * 1;
            }
            else if (CameraController.cameralook == CameraLook.Forward)
            {
                blockBase.transform.position -= Vector3.back * 1;
            }
            else if (CameraController.cameralook == CameraLook.Top)
            {
                blockBase.transform.position -= Vector3.up * 1;
            }
            TimeAction.Delay(1, () => { blockBase.transform.position = pos; });
        }
    }

    public override void TriggerOff()
    {
        materialAnimation.Play(1);
        boxCollider.enabled = true;
        LevelManager.instance.BuildNavMesh();
        BlockBase blockBase = LevelManager.instance.FindLastBlock(transform.position, this);
        if (blockBase != null)
        {
            blockBase.gameObject.SetActive(false);
        }
    }
}
